<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            position: fixed;
            width: 200px;
            height: 200px;
            background-color: rgb(255, 241, 0);

        }
    </style>
</head>

<body>
    <div></div>
    <script>
        var div = document.querySelector('div');

        div.addEventListener('mousedown', function (e) {
            var innerX = e.pageX - div.offsetLeft;
            var innerY = e.pageY - div.offsetTop;
            document.addEventListener('mousemove',move)
            function move(e) {
                div.style.left = e.pageX - innerX + 'px';
                div.style.top = e.pageY - innerY + 'px';
            }
            document.addEventListener('mouseup', function (e) {
                document.removeEventListener('mousemove', move);
            })
        })



    </script>
</body>

</html>